package com.rybbaby.tss.front.tssPackagePostpone.dao.imp;

import com.rybbaby.tss.core.web.dao.imp.GenericDao;
import com.rybbaby.tss.front.tssPackagePostpone.dao.ITssPackagePostponeDao;
import com.rybbaby.tss.front.tssPackagePostpone.entity.TssPackagePostpone;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @description 课时包延期表数据库操作实现
 * 
 * @author 雷春琼
 * 
 * @createDate 2017-08-25 下午5:12:18
 */
@Repository
public class TssPackagePostponeDaoImp extends GenericDao<TssPackagePostpone> implements ITssPackagePostponeDao {

    @Override
    public List<Map<String, Object>> tssPackagePostponeListByMemberId(String memberId,String memberPackageId) {
        String  sql="SELECT\n" +
                "\tmp.attendedDay,\n" +
                "\tmp.surplusValidDate,\n" +
                "\tmp.packageStatus,\n" +
                "\t(\n" +
                "\t\tSELECT\n" +
                "\t\t\tcount(1)\n" +
                "\t\tFROM\n" +
                "\t\t\ttss_package_postpone\n" +
                "\t\tWHERE\n" +
                "\t\t\tmemberPackageId = mp.id\n" +
                "\t) postponeCount,\n" +
                "\t(\n" +
                "\t\tSELECT\n" +
                "\t\t\tremark\n" +
                "\t\tFROM\n" +
                "\t\t\ttss_package_postpone\n" +
                "\t\tWHERE\n" +
                "\t\t\tmemberPackageId = mp.id\n" +
                "\t\tORDER BY\n" +
                "\t\t\tcreateTime DESC\n" +
                "\t\tLIMIT 1\n" +
                "\t) remark,\n" +
                "\tmp.memberId,\n" +
                "\tp. NAME,\n" +
                "\t mp.id memberPackageId,\n" +
                "\t mp.surplusClassHour\n" +
                "FROM\n" +
                "\ttss_member_package mp\n" +
                "LEFT JOIN tss_package p ON p.id = mp.packageId\n" +
                "LEFT JOIN tss_package_postpone pp ON pp.memberPackageId = mp.id\n" +
                "WHERE\n" +
                "\tmp.memberId = ?\n" +
                "\t and mp.id=?\n" +
                "GROUP BY\n" +
                "\tpackageId";
        return this.findForJdbc(sql,new Object[]{memberId,memberPackageId});
    }

    @Override
    public List<Map<String, Object>> getDetailListByMemberId(String memberId, Integer type) {
        String sql="SELECT\n" +
                "\tpp.createTime,\n" +
                "\tpp.remark,\n" +
                "\te.userName\n" +
                "FROM\n" +
                "\ttss_package_postpone pp\n" +
                "LEFT JOIN tss_member_package mp ON mp.id = pp.memberPackageId\n" +
                "LEFT JOIN sys_admin_user e ON e.id = pp.adminUserId\n" +
                "WHERE\n" +
                "\tmp.memberId = ?\n" +
                "AND mp.type = ?";
       return this.findForJdbc(sql,new Object[]{memberId,type});
    }
}
